//
//  ContentView.swift
//  WidgetExample
//
//  Created by Ben on 2022/4/7.
//

import SwiftUI
import WidgetKit



// 从本期视频开始，up主将分大概三期视频来演示如何使用小组件Widget
// 这是一个空白的项目，首先给项目添加Widget扩展
struct ContentView: View {
    
//    @State private var showWeek: Bool = true
    @StateObject var widgetVM: WidgetViewModel = WidgetViewModel()
    
    var body: some View {
        NavigationView {
            Form {
                Section(header: Text("时钟组件")) {
                    
                    Toggle("显示星期", isOn: $widgetVM.timeWidgetShowWeek)
                }
            }
            .navigationTitle("组件设置")
        }
        .onAppear {
            UserDefaultGroup.shared.timeWidgetTypeList = [.normal, TimeWidgetTypeModel(id: "2", name: "数字时钟", type_value: TimeWidgetStyle.electronic.rawValue)]
            
            print(UserDefaultGroup.shared.timeWidgetTypeList.count)
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
